using System;
using System.Data.Odbc;
using System.Data.OracleClient;
using System.Reflection;
using ODX.Core;

namespace CreateUpgrade
{
    [Table]
    public abstract class Person : Entity
    {
        public abstract string Name { get; set;}
        public abstract string Name2 { get; set;}
        public abstract double Weight { get; set;}
        public abstract decimal Salary { get; set;}
        public abstract DateTime DateOfBirth { get; set; }
        public abstract IEntityList<Pet> Pets { get; }

        public abstract Person Chief { get; set; }
    }

    [Table]
    [UniqueConstraint("Name", "MasterID")]
    public abstract class Pet : Entity
    {
        [Column(Unique = true, MaxLength = 150)]
        public abstract string Name { get; set;}
        public abstract Person Master { get; set; }
    }

    class Program
    {
        static void Main()
        {

            DbDataProvider provider = new DbDataProvider(OracleClientFactory.Instance, "User Id=odx;Password=odx");
            //DbDataProvider provider = new DbDataProvider(OdbcFactory.Instance, "Driver={PostgreSQL ANSI};Server=localhost;Database=test;Uid=postgres;Pwd=private;");
            Session s = new Session(provider, Assembly.GetExecutingAssembly());

            provider.PrepareDatabase(s.Schema);

            Person p = s.Create<Person>();
            p.Name = "Third";
            p.Name2 = "Second - pt.II";

            p.Chief = s.SelectOne<Person>("Name = 'First'");

            s.Save();
        }
    }
}
